﻿using Artech.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Artech.Core.Configuration
{
    /// <summary>
    /// The application context based <see cref="ConfigurationSection"/>.
    /// </summary>
    public class ApplicationContextSettings: ServiceLocatableConfigurationSection
    {
        private const string PropertyName4DefaultContextProvider = "defaultContextProvider";
        private const string PropertyName4ContextProviders = "contextProviders";

        /// <summary>
        /// Gets or sets the default context provider.
        /// </summary>
        /// <value>
        /// The default context provider.
        /// </value>
        [ConfigurationProperty(PropertyName4DefaultContextProvider, IsRequired = true)]
        public string DefaultContextProvider
        {
            get { return (string)base[PropertyName4DefaultContextProvider]; }
            set { base[PropertyName4DefaultContextProvider] = value; }
        }

        /// <summary>
        /// Gets or sets the context providers.
        /// </summary>
        /// <value>
        /// The context providers.
        /// </value>
        [ConfigurationProperty(PropertyName4ContextProviders, IsRequired = true)]
        public NameTypeConfigurationElementCollection<ContextProviderDataBase, CustomContextProviderData> ContextProviders
        {
            get
            {
                return (NameTypeConfigurationElementCollection<ContextProviderDataBase, CustomContextProviderData>)base[PropertyName4ContextProviders];
            }
            set
            {
                base[PropertyName4ContextProviders] = value;
            }
        }

        /// <summary>
        /// Gets the current <see cref="ApplicationContextSettings"/>.
        /// </summary>
        /// <returns>The current <see cref="ApplicationContextSettings"/>.</returns>
        public static ApplicationContextSettings GetSettings()
        {
            return ConfigurationSourceManager.Current.GetConfigurationSection<ApplicationContextSettings>(Constants.ConfigurationSections.ApplicationContext);
        }
    }
}
